import numpy as np
import matplotlib.pyplot as plt

def ydot(t, y):
    z = np.zeros(2)
    z[0] = y[1]**2 - 2 * y[0]
    z[1] = y[0] - y[1] - t * (y[1] ** 2)
    return z

def eulerstep(t, y, h):
    result = y + h * ydot(t, y)
    return result

def euler2(inter, y0, n):
    t = np.zeros(n+1)
    t[0] = inter[0]

    y = np.zeros((n+1, 2))
    y[0, :] = y0
    h = (inter[1] - inter[0])/n

    for i in range(0, n):
        t[i+1] = t[i] + h
        y[i+1, :] = eulerstep(t[i], y[i, :], h)
    
    f = plt.figure()
    plt.plot(t, y[:, 0])
    f.hold()
    plt.plot(t, y[:, 1])
    plt.show()

if __name__ == "__main__":
    euler2([0, 1], [0, 1], 10)